home *** CD-ROM | disk | FTP | other *** search
/ Aminet 44 / Aminet 44 (2001)(GTI - Schatztruhe)[!][Aug 2001].iso / Aminet / dev / src / Rkm_asm.lha / Assembly_Codes / OS_Sources / Exec / Wait.s < prev    next >
Text File  |  1992-09-02  |  8KB  |  377 lines

  1.  
  2.  * This code shows how to Wait for a specific Signal.
  3.  
  4.     INCDIR    WORK:Include/
  5.  
  6.     INCLUDE    exec/exec_lib.i
  7.     INCLUDE    exec/memory.i
  8.     INCLUDE    intuition/intuition_lib.i
  9.     INCLUDE    intuition/intuition.i
  10.     INCLUDE dos/dos_lib.i
  11.     INCLUDE dos/dos.i
  12.     INCLUDE dos/dosextens.i
  13.     INCLUDE    workbench/icon_lib.i
  14.     INCLUDE    workbench/startup.i
  15.     INCLUDE    workbench/workbench.i
  16.  
  17. LIB_VER        EQU    39
  18. TRUE        EQU    -1
  19. FALSE        EQU    0
  20.  
  21.     lea    membuf(pc),a4
  22.  
  23.  * membuf (Memory Buffer) is set-up so that this code can be
  24.  * position-independant. The memory buffer contains the following
  25.  * addresses and their data:
  26.  *
  27.  *   0  Startup Return Message
  28.  *   4  _DOSBase
  29.  *   8  _IntuitionBase
  30.  *  12 _IconBase
  31.  *  16 Old Directory from CurrentDir()
  32.  *  20 Disk Object from GetDiskObject()
  33.  *  24 Argument addresses (30*4)
  34.  * 144 ReadArgs() return value
  35.  * 148 Task address
  36.  * 152 _GfxBase
  37.  * 156
  38.  * 160
  39.  * 164
  40.  * 165
  41.  * 166 Memory Buffer (12 bytes)
  42.  * 178
  43.  * 182 value 1 (for ToolType/CLI result)
  44.  * 183 value 2 (for ToolType/CLI result)
  45.  * 184
  46.  
  47.  * The Startup code below reads two CLI Arguments/WB ToolTypes as an example
  48.  * of how to programme CLI Arguments/WB ToolTypes.
  49.  *
  50.  * Note: The CLI Arguments/WB ToolTypes are done after Startup and Library
  51.  *       opening, so there is no use for the A0 pointer (which contains
  52.  *       pr_CLI).
  53.  
  54.     suba.l    a1,a1
  55.     move.l    4.w,a6
  56.     jsr    _LVOFindTask(a6)
  57.     tst.l    d0
  58.     beq    exit
  59.     move.l    d0,a5
  60.     move.l    a5,148(a4)
  61.     tst.l    pr_CLI(a5)        ; Was this task started from CLI?
  62.     bne.s    _main            ; Yes.
  63.     lea    pr_MsgPort(a5),a0    ; No. From Workbench.
  64.     jsr    _LVOWaitPort(a6)
  65.     lea    pr_MsgPort(a5),a0
  66.     jsr    _LVOGetMsg(a6)
  67.     move.l    d0,(a4)            ; D0 = A WBStartup Message.
  68.  
  69. _main
  70.     moveq    #LIB_VER,d0
  71.         lea     dos_name(pc),a1
  72.     move.l    4.w,a6
  73.         jsr    _LVOOpenLibrary(a6)
  74.         move.l  d0,4(a4)
  75.         beq     quit
  76.  
  77.         moveq    #LIB_VER,d0
  78.         lea     int_name(pc),a1
  79.         jsr    _LVOOpenLibrary(a6)
  80.         move.l  d0,8(a4)
  81.         beq     cl_dos
  82.  
  83.         moveq    #LIB_VER,d0
  84.         lea     gfx_name(pc),a1
  85.         jsr    _LVOOpenLibrary(a6)
  86.         move.l  d0,152(a4)
  87.         beq     cl_int
  88.  
  89.         moveq    #LIB_VER,d0
  90.         lea     icon_name(pc),a1
  91.         jsr    _LVOOpenLibrary(a6)
  92.         move.l  d0,12(a4)
  93.         beq     cl_gfx
  94.  
  95.  * Check the ToolTypes/CLI Arguments.
  96.  
  97.         move.l    (a4),a0
  98.         tst.l   a0
  99.         beq    fromcli
  100.     move.l    sm_ArgList(a0),a5
  101.         move.l  (a5),d1
  102.     beq    zero_args
  103.     move.l    4(a4),a6
  104.     jsr    _LVOCurrentDir(a6)
  105.         move.l  d0,16(a4)
  106.         move.l    wa_Name(a5),a0
  107.     move.l    12(a4),a6
  108.     jsr    _LVOGetDiskObject(a6)
  109.         move.l  d0,20(a4)
  110.         beq     zero_args
  111.         move.l    d0,a5
  112.         move.l  do_ToolTypes(a5),a5
  113.  
  114.     move.l    a5,a0
  115.         lea    ftstg0(pc),a1
  116.         jsr    _LVOFindToolType(a6)
  117.     tst.l    d0
  118.         beq.s    tt1
  119.     move.l    d0,a3
  120.     move.l    a3,a0
  121.     lea    mtstg0(pc),a1
  122.     jsr    _LVOMatchToolValue(a6)
  123.     tst.l    d0
  124.     beq.s    tto1
  125.     clr.b    182(a4)
  126.     bra.s    tt1
  127. tto1    move.l    a3,a0
  128.     lea    mtstg1(pc),a1
  129.     jsr    _LVOMatchToolValue(a6)
  130.     tst.l    d0
  131.     beq.s    tt1
  132.     move.b    #1,182(a4)
  133. tt1    move.l    a5,a0
  134.         lea    ftstg1(pc),a1
  135.         jsr    _LVOFindToolType(a6)
  136.     tst.l    d0
  137.         beq.s    tt2
  138.     move.l    d0,a3
  139.     move.l    a3,a0
  140.     lea    mtstg2(pc),a1
  141.     jsr    _LVOMatchToolValue(a6)
  142.     tst.l    d0
  143.     beq.s    tto2
  144.     clr.b    183(a4)
  145.     bra.s    tt2
  146. tto2    move.l    a3,a0
  147.     lea    mtstg3(pc),a1
  148.     jsr    _LVOMatchToolValue(a6)
  149.     tst.l    d0
  150.     beq.s    tto3
  151.     move.b    #1,183(a4)
  152.     bra.s    tt2
  153. tto3    move.l    a3,a0
  154.     lea    mtstg4(pc),a1
  155.     jsr    _LVOMatchToolValue(a6)
  156.     tst.l    d0
  157.     beq.s    tto4
  158.     move.b    #2,183(a4)
  159.     bra.s    tt2
  160. tto4    move.l    a3,a0
  161.     lea    mtstg5(pc),a1
  162.     jsr    _LVOMatchToolValue(a6)
  163.     tst.l    d0
  164.     beq.s    tt2
  165.     move.b    #3,183(a4)
  166. tt2
  167.     nop
  168.  
  169.  
  170. free_diskobj
  171.         move.l    20(a4),a0
  172.         jsr    _LVOFreeDiskObject(a6)
  173.     bra    zero_args
  174.  
  175. fromcli    lea    template(pc),a0
  176.     move.l  a0,d1
  177.         lea    24(a4),a5
  178.         move.l  a5,d2
  179.         moveq    #0,d3
  180.     move.l    4(a4),a6
  181.         jsr    _LVOReadArgs(a6)
  182.         move.l  d0,144(a4)
  183.         beq    zero_args
  184.  
  185.     move.l    (a5),a0
  186.     lea    mtstg0(pc),a1
  187.     bsr    cmpbyte
  188.     tst.l    d0
  189.     bne.s    cao1
  190.     clr.b    182(a4)
  191.     bra.s    ca1
  192. cao1    move.l    (a5),a0
  193.     lea    mtstg1(pc),a1
  194.     bsr    cmpbyte
  195.     tst.l    d0
  196.     bne.s    ca1
  197.     move.b    #1,182(a4)
  198. ca1    move.l    4(a5),a0
  199.     lea    mtstg2(pc),a1
  200.     bsr    cmpbyte
  201.     tst.l    d0
  202.     bne.s    cao2
  203.     clr.b    183(a4)
  204.     bra.s    ca2
  205. cao2    move.l    4(a5),a0
  206.     lea    mtstg3(pc),a1
  207.     bsr    cmpbyte
  208.     tst.l    d0
  209.     bne.s    cao3
  210.     move.b    #1,183(a4)
  211.     bra.s    ca2
  212. cao3    move.l    4(a5),a0
  213.     lea    mtstg4(pc),a1
  214.     bsr    cmpbyte
  215.     tst.l    d0
  216.     bne.s    cao4
  217.     move.b    #2,183(a4)
  218.     bra.s    ca2
  219. cao4    move.l    4(a5),a0
  220.     lea    mtstg5(pc),a1
  221.     bsr    cmpbyte
  222.     tst.l    d0
  223.     bne.s    ca2
  224.     move.b    #3,183(a4)
  225. ca2
  226.     nop
  227.  
  228.  
  229. free_cliargs
  230.         move.l    144(a4),d1
  231.         jsr    _LVOFreeArgs(a6)
  232.  
  233. zero_args
  234.  
  235.     moveq    #0,d5
  236.     moveq    #-1,d0
  237.     move.l    4.w,a6
  238.     jsr    _LVOAllocSignal(a6)
  239.     move.b    d0,d5                ; Signal Bit (a #bit between 0 and 31)
  240.     cmp.l    #-1,d0
  241.     beq.s    cl_icon
  242.  
  243.     moveq    #0,d6
  244.     bset    d5,d6                ; Set the `signal bit' of d6. So. If
  245.                                      ; the `signal bit' (inside d5) is 29
  246.                                      ; d6 will have its 29th bit set. d6 is
  247.                                      ; then known as the `signal Mask'.
  248.  
  249.     bset    #12,d6               ; Set the SIGBREAKF_CTRL_C bit aswell.
  250.  
  251.  * The Wait() instruction waits for another task (program) to signal this
  252.  * task (program). In the meantime it puts this task to sleep (in the
  253.  * waiting state). It is waiting for a signal mask (a 32 bit signal). Wait
  254.  * waits only for those signals (bits) you have set inside the signal mask.
  255.  * It does not wait for any other signals (bits). So if it only waiting for
  256.  * signals 29 and 12 for example it will not awaken this task if it receives
  257.  * signal 23.
  258.  
  259. waiting    move.l    d6,d0
  260.     jsr    _LVOWait(a6)          ; Wait for another task to signal us.
  261.     move.l    d0,d4              ; d4 contains a Signal Mask of signals
  262.                       ; this task/wait has received.
  263.  
  264.  
  265.     move.l    d4,d0              ; It is up to you to check each signal
  266.     and.l    #SIGBREAKF_CTRL_C,d0  ; by ANDing the signal mask.
  267.     cmpi.l    #SIGBREAKF_CTRL_C,d0  ; did I receive a Ctrl_C signal?
  268.     beq.s    ctrl_c              ; yes. so exit.
  269.     bne.s    waiting              ; no. so wait() again.
  270.  
  271.     suba.l    a0,a0              ; yes. so exit with a flash.
  272.     move.l    8(a4),a6
  273.     jsr    _LVODisplayBeep(a6)
  274.     bra.s    cl_icon
  275.  
  276. ctrl_c    moveq    #100,d1
  277.     move.l    4(a4),a6
  278.     jsr    _LVODelay(a6)
  279.  
  280.     suba.l    a0,a0
  281.     move.l    8(a4),a6
  282.     jsr    _LVODisplayBeep(a6)
  283.  
  284.     moveq    #100,d1
  285.     move.l    4(a4),a6
  286.     jsr    _LVODelay(a6)
  287.  
  288.     suba.l    a0,a0
  289.     move.l    8(a4),a6
  290.     jsr    _LVODisplayBeep(a6)
  291.  
  292.  
  293. cl_icon    move.l  12(a4),a1
  294.     move.l    4.w,a6
  295.         jsr    _LVOCloseLibrary(a6)
  296.  
  297. cl_gfx    move.l  152(a4),a1
  298.     move.l    4.w,a6
  299.         jsr    _LVOCloseLibrary(a6)
  300.  
  301. cl_int    move.l  8(a4),a1
  302.     move.l    4.w,a6
  303.         jsr    _LVOCloseLibrary(a6)
  304.  
  305. cl_dos    move.l  4(a4),a1
  306.     move.l    4.w,a6
  307.         jsr    _LVOCloseLibrary(a6)
  308.  
  309. quit    move.l  #8000000,d0
  310.         moveq    #MEMF_CHIP,d1
  311.     move.l    4.w,a6
  312.     jsr    _LVOAllocMem(a6)
  313.     tst.l    d0
  314.     beq.s    cleanup
  315.     move.l    d0,a1
  316.     move.l    #8000000,d0
  317.     jsr    _LVOFreeMem(a6)
  318. cleanup    tst.l    (a4)
  319.     beq.s    exit            ; Exit - Task was started from CLI.
  320.     move.l    4.w,a6
  321.     jsr    _LVOForbid(a6)
  322.     move.l    (a4),a1            ; Reply to the WB Startup Message and
  323.     jsr    _LVOReplyMsg(a6)    ; Exit - Task was started from WB.
  324. exit    moveq    #0,d0
  325.     rts
  326.  
  327.  
  328.  * Sub-Routines.
  329.  
  330. cmpbyte    move.b  (a0)+,d0
  331.         move.b  (a1)+,d1
  332.         tst.b   d0
  333.         beq.s   byte0
  334.         cmp.b   d1,d0
  335.         beq.s   cmpbyte
  336. byte0    sub.b   d1,d0
  337.         ext.w   d0
  338.         ext.l   d0
  339.         rts
  340.  
  341. findlen    move.l    a0,a1
  342.     moveq    #0,d0
  343. not_nil    tst.b    (a1)+
  344.     beq.s    gotlen
  345.     addq.l    #1,d0
  346.     bra.s    not_nil
  347. gotlen    rts
  348.  
  349.  
  350.  * String Variables.
  351.  
  352. int_name    dc.b    'intuition.library',0
  353. dos_name    dc.b    'dos.library',0
  354. icon_name       dc.b    'icon.library',0,0
  355. gfx_name    dc.b    'graphics.library',0
  356. mtstg0        dc.b    'ARG_ONE',0
  357. mtstg1        dc.b    'ARG_TWO',0
  358. mtstg2        dc.b    'ARG_THREE',0
  359. mtstg3        dc.b    'ARG_FOUR',0,0
  360. mtstg4        dc.b    'ARG_FIVE',0,0
  361. mtstg5        dc.b    'ARG_SIX',0
  362. ftstg0          dc.b    'TOOLTYPE_ONE',0,0
  363. ftstg1          dc.b    'TOOLTYPE_TWO',0,0
  364. template    dc.b    'KEYWORD_ONE/K,KEYWORD_TWO/K',0
  365.  
  366.  
  367.  * Buffer Variables.
  368.  
  369. membuf        dcb.b    200,0
  370.  
  371.  
  372.     SECTION    VERSION,DATA
  373.  
  374.     dc.b    '$VER: Wait.s V1.01 (22.4.2001)',0
  375.  
  376.  
  377.     END